创建的sheet如下:# -*- coding: utf-8 -*-from openpyxl import Workbookwb = Workbook()ws1 = wb.create_sheet("Mysheet") #创建一个sheetws1.title = "New Title" #设定一个sheet的名字ws2 = wb.create_sheet("Mysheet", 0) #设定sheet的插入位置 默认插在后面ws2.title = (u"你好") #设定一个sheet的名字 必须是Unicodews1.sheet_properties.tabColor = "1072BA" #设定sheet的标签的背景颜色#获取某个sheet对象print (wb.get_sheet_by_name(u"你好" ))print (wb["New Title" ])#获取全部sheet 的名字,遍历sheet名字print (wb.sheetnames)for sheet_name in wb.sheetnames: print (sheet_name)print ("*"*50)for sheet in wb: print (sheet.title)#复制一个sheetwb["New Title" ]["A1"]="zeke"source = wb["New Title" ]target = wb.copy_worksheet(source)# w3 = wb.copy_worksheet(wb['new title'])# ws3.title = 'new2'# wb.copy_worksheet(wb['new title']).title = 'hello'# Save the filewb.save("d:\\sample.xlsx")
评论